package org.xq.softcup.mq.util;

import java.util.concurrent.*;

public class ThreadPoolUtil {
    public static ThreadPoolExecutor makeServerThreadPool(final String serverType) {
        ThreadPoolExecutor serverHandlerPool = new ThreadPoolExecutor(60, 300, 60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue(1000),
                new ThreadFactory(){
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r, serverType + "-serverHandlerPool-" + r.hashCode());
                    }
                },
                new RejectedExecutionHandler() {
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        throw new XQRpcException(serverType + " 线程池已满载!");
                    }
                });
        return serverHandlerPool;
    }
}
